# -*- coding:UTF-8 -*-
from cmdb.models import RoomNoInfo

#获取所有房间号
def get_room_no_infos():
    roomNoRes = RoomNoInfo.objects.all()
    return roomNoRes

#通过id获取当个机房房间号
def get_room_no(id):
    roomNoInfo = RoomNoInfo.objects.get(id=id)
    return roomNoInfo

#通过机房id获取对应的所有房间号
def filter_room_no(server_room_id):
    roomNoInfo = RoomNoInfo.objects.filter(server_room_id=server_room_id)
    return roomNoInfo

#判断机房号是否存在
def exists_room_no(id):
    roomNoCount = RoomNoInfo.objects.filter(id=id).count()
    if roomNoCount > 0:
        return True
    return False

def add_room_no_info(room_no, server_room_id, cursor):
    room_no_add_sql = 'insert into room_no_info set room_no="' + room_no + '",server_room_id=' + server_room_id
    cursor.execute(room_no_add_sql)

def del_room_no_info(server_room_id, cursor):
    room_no_del = 'delete from room_no_info where server_room_id=' + server_room_id;
    cursor.execute(room_no_del)